<?php
// +----------------------------------------------------------------------
// | Author: 发仔 <i@fazi.me> 
// +----------------------------------------------------------------------

namespace app\unit\controller;

use think\Db;

class Driver extends Base
{
	protected $id = 'driver_id';
	protected $table = 'driver';
	protected $joins = [
        ['company c','c.company_id = m.company_id','left'],
        ['user u','u.user_id = m.user_id','left']
    ];
    protected $field = 'm.*,c.company_name,u.username';

    protected function parseData($data = []) {

        $data = parent::parseData($data);
        unset($data['username']);
        //公司ID关联
//        $company_id = $data['company_id'];
//        $userId      = $data['user_id'];

        //取消自动绑定 2018-07-17 BY 发仔
//        if($userId==0){
//            $user = [];
//            $user['salt'] = substr(uniqid(), -6);
//            $user['password'] = CorePwd('111111',$user['salt']);
//            $user['role_id']  = 5;
//            $user['username'] = $data['phone'];
//            $user['mobile']   = $data['phone'];
//            $user['area_id']  = Db::name('company')->where('company_id',$company_id)->value('area_id');
//            $repeat = Db::name('user')->where('username|mobile',$data['phone'])->whereNull('delete_time')->find();
//            if($repeat) {
//                return $this->error('手机已存在，用户添加失败，请修改手机');
//            }
//            $data['user_id'] = Db::name('user')->insertGetId($user);
//        } elseif($data['password']) {
//            $user['salt'] = substr(uniqid(), -6);
//            $user['password'] = CorePwd($data['password'],$user['salt']);
//
//            Db::name('user')->where('user_id',$userId)->update($user);
//
//        }

        $data['edit_time'] = time();
//        unset($data['password']);

        return $data;
    }

}
